<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/24 0024
 * Time: 17:04
 */

namespace app\storage\controller;


use app\storage\model\SmtMaterielModel;
use app\storage\service\CommonService;
use cmf\controller\AdminBaseController;
use think\Request;

class SmtmaterielController extends AdminBaseController
{
    protected $smtMaterielModel;
    protected $commonService;
    use \app\storage\util\Common;
    /**
     * SmtmaterielController constructor.
     * @param Request|null $request
     * @param SmtMaterielModel $smtMaterielModel
     * @param CommonService $commonService
     */
    public function __construct(Request $request = null, SmtMaterielModel $smtMaterielModel,  CommonService $commonService)
    {
        parent::__construct($request);
        $this->smtMaterielModel = $smtMaterielModel;
        $this->commonService = $commonService;
    }

    /***
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 物料信息展示视图
     */
    public function index()
    {
        $storageUuid = input('storageUuid');
        $storageInfo = $this->commonService->get_assign_storage($storageUuid);
        $assign['storageUuid'] = $storageUuid;
        $assign['storageInfo'] = $storageInfo;
        $this->assign($assign);
        return $this->fetch('index');
    }

    /***
     * @return \think\response\Json
     * 获取物料信息（展示）
     */
    public function getMateriel()
    {
        $where = $this->getWhere();
        $result = $this->smtMaterielModel->getSmtMateriel($where);
        return json($result);
    }
}